package com.hc.race.controller;

import com.hc.race.dto.Result;
import com.hc.race.entity.Challenges;
import com.hc.race.service.ChallengeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author zy
 * @Date 2023/11/25 11:56
 * @PackageName:com.hc.race.controller
 * @ClassName: ChallengeController
 * @Description: TODO
 * @Version 1.0
 */
@RestController
@RequestMapping("challenge")
public class ChallengeController {
    @Autowired
    private ChallengeService challengeService;


    @GetMapping("/info")
    public Result<List<Challenges>> getInfo(@RequestParam Long userId) {
        List<Challenges> challengesList = challengeService.getInfo(userId);
        return Result.success(challengesList);
    }

    @GetMapping("/{id}")
    public Result<Challenges> getSingleInfo(@PathVariable Long id) {
        Challenges challenge = challengeService.getSingleInfo(id);
        if (challenge != null) {
            return Result.success(challenge);
        } else {
            return Result.error("没有数据");
        }
    }
}
